package com.nintendo.tool;

import com.nintendo.entity.Content;
import com.nintendo.entity.Doc;
import com.nintendo.entity.Ebook;
import com.nintendo.mapper.EbookMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Component
@Slf4j
public class EbookTool {
    @Autowired
    private EbookMapper ebookMapper;
    @Tool(description = "根据name查询出书籍中的内容,把他总结返回给用户就行,不用去猜测这本书是干啥的,书中有什么样的内容,你就讲述什么样的内容")
    public String selectEbookByName(String name){
        log.info("<------------------------讲述书籍信息-------------------------->");
        Ebook ebook = ebookMapper.selectByName(name);
        Long ebookId = ebook.getId();
        List<Doc> docList = ebookMapper.findDocByEbookId(ebookId);
        log.info("docList--------------------->{}",docList);
        List<Long> contentIds = docList.stream().map(Doc::getId).toList();
        log.info("contentIds--------------------->{}",contentIds);
        List<Content> contentList = ebookMapper.findContentByIds(contentIds);
        log.info("contentList--------------------->{}",contentList);
        List<String> content = contentList.stream().map(Content::getContent).toList();
        log.info("content--------------------->{}",content);
        log.info("<------------------------结束书籍信息-------------------------->");
        // 拼接成字符串
        StringBuilder sb = new StringBuilder();
        for (String s : content) {
            sb.append(s);
        }
        return sb.toString();
    }

}
